home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_2.arc / WINDEV2.ARC / WINAUXFN.C < prev    next >
Text File  |  1988-12-04  |  3KB  |  132 lines

  1. /* 
  2.  * Winaux functions module
  3.  *
  4.  * Written by Bill Hall
  5.  * 3665  Benton Street, #66
  6.  * Santa Clara, CA 95051
  7.  *
  8.  */
  9.  
  10. #define NOCOMM
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <ascii.h>
  14. #include <windows.h>
  15. #include <ttycls.h>
  16. #include "winaux.h"
  17.  
  18. /* local function declaractions */
  19. static void NEAR ShowAboutBox(HWND hWnd);
  20.  
  21. void NEAR DispatchString(HWND hWnd, WORD wParam, LONG lParam)
  22. {
  23.  
  24.     BYTE buf[100];
  25.     int len, i;
  26.     
  27.     len = min((int)wParam, 100);
  28.     for (i = 0; i < len; i++)
  29.     buf[i] = *(LPSTR)(lParam + i);
  30.     TTYDisplay((PTTYWND)GetWindowWord(hWnd,0),(short)len, buf);
  31. }
  32.  
  33. static void NEAR ShowAboutBox(HWND hWnd)
  34. {
  35.  
  36.     FARPROC fp;
  37.     HANDLE hInstance = GetWindowWord(hWnd, GWW_HINSTANCE);
  38.  
  39.   /* make a proc instance for the about box window function */
  40.     fp = MakeProcInstance((FARPROC)AboutBoxProc, hInstance);
  41.   /* create a modal dialog box */
  42.     DialogBox(hInstance, MAKEINTRESOURCE(DT_ABOUT),hWnd,fp);
  43. }
  44.  
  45. /* process the menu */
  46. void NEAR WndCommand(HWND hWnd, WORD wParam)
  47. {
  48.  
  49.     HMENU hMenu = GetMenu(hWnd);
  50.  
  51.     switch (wParam) {
  52.  
  53.     case IDM_ABOUT:
  54.         ShowAboutBox(hWnd);
  55.         break;
  56.  
  57.     case IDM_CRONLF:
  58.         MWnd.CRonLF = (MWnd.CRonLF ? FALSE : TRUE);
  59.         CheckMenuItem(hMenu,wParam,MWnd.CRonLF ? MF_CHECKED : MF_UNCHECKED);
  60.         break;
  61.     }
  62. }
  63.  
  64. /* paint the main window */
  65. void NEAR MainWndPaint(hWnd, lpps)
  66. HWND hWnd;
  67. LPPAINTSTRUCT lpps;
  68. {
  69.  
  70.     HDC hDC = lpps->hdc;
  71.  
  72.   /* if the window is iconic, draw the icon */
  73.     if (IsIconic(hWnd)) {
  74.     RECT rIcon;
  75.     GetClientRect(hWnd, (LPRECT)&rIcon);
  76.     Rectangle(hDC, 0,0,rIcon.right, rIcon.bottom);
  77.         TextOut(hDC,2,rIcon.bottom/3,(LPSTR)szIconTitle,strlen(szIconTitle));
  78.     }
  79.   /* otherwise update the text in the window */
  80.     else 
  81.     TTYWndPaint(&MWnd, lpps->hdc, lpps->rcPaint.top, lpps->rcPaint.bottom);
  82. }
  83.  
  84. /* set the window handle variable */
  85. int SetWinIni(HWND hWnd)
  86. {
  87.     char buf[20];
  88.     return (WriteProfileString((LPSTR)szAppName, (LPSTR)szhWnd, 
  89.             (LPSTR)itoa(hWnd, buf, 10)));
  90. }
  91.  
  92. /* adjust where text is to be displayed if window is resized */
  93. void NEAR AdjustHeight(short width, short height)
  94. {
  95.      
  96.     MWnd.Width = width;
  97.     MWnd.Height = height;
  98.     MWnd.Pos.y = height - MWnd.CHeight - 1;
  99.     InvalidateRect(MWnd.hWnd, (LPRECT)NULL, TRUE);
  100. }
  101.  
  102. /* This is the window proc for the about box when it is displayed */
  103. BOOL FAR PASCAL AboutBoxProc(hDlg, message, wParam, lParam)
  104. HWND hDlg;
  105. unsigned message;
  106. WORD wParam;
  107. LONG lParam;
  108. {
  109.  
  110.     switch (message) {
  111.  
  112.       /* nothing to initialize */
  113.     case WM_INITDIALOG:
  114.         break;
  115.  
  116.       /* this dialog box has only an OK button */
  117.     case WM_COMMAND:
  118.         switch (wParam) {
  119.         case IDOK:
  120.         /* destroy the dialog box */
  121.             EndDialog(hDlg,TRUE);
  122.             break;
  123.         default:
  124.             return FALSE;        /* we did not process */
  125.         }
  126.  
  127.     default:
  128.         return FALSE;
  129.     }
  130.     return TRUE;        /* we processed message */
  131. }
  132.